package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.SettingsVo;
import com.tanhua.server.service.SettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/users")
public class SettingsController {

    @Autowired
    private SettingsService settingsService;

    /**
     * 用户通用设置 - 读取
     * @return
     */
    @GetMapping("/settings")
    public ResponseEntity settings(){
        SettingsVo vo = settingsService.settings();
        return ResponseEntity.ok(vo);
    }

    /**
     * 通知设置 - 修改保存
     * @return
     */
    @PostMapping("/notifications/setting")
    public ResponseEntity settingUpdate(@RequestBody Map map){
        settingsService.settingsUpdate(map);
        return ResponseEntity.ok(null);
    }

     /**
     * 保存问题
     * @param map
     * @return
     */
    @PostMapping("/questions")
    public ResponseEntity questions(@RequestBody Map map){
        String content = (String) map.get("content");
        settingsService.saveQuestion(content);
        return ResponseEntity.ok(null);
    }

    /**
     * 查询黑名单列表
     * @param page 当前展示的页数
     * @param pagesize 当前页面展示的条数
     * @return
     */
    @GetMapping("/blacklist")
    public ResponseEntity blacklist(@RequestParam(defaultValue = "1") int page,@RequestParam(defaultValue = "10") int pagesize){
        //调用黑名单查找方法
        PageResult blacklist = settingsService.blacklist(page, pagesize);
        return ResponseEntity.ok(blacklist);
    }

    /**
     * 黑名单 - 移除
     * 通过通过黑名单id进行删除
     * @return
     */
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity blacklistDelete(@PathVariable Long uid){
        settingsService.blackByIdDelete(uid);
        return ResponseEntity.ok(null);
    }
}
